package cn.eric.tests;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.Enumeration;

public class HelloWorldController implements Controller {
    @Override
    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        // 设置参数
//        String user = httpServletRequest.getParameter("user");
//        System.out.println("hello spring mvc:"+user);
        // 回显 参数
//        httpServletRequest.setAttribute("msg","hello srping mvc");
//        httpServletRequest.getRequestDispatcher("/WEB-INF/view/hello.jsp").forward(httpServletRequest,httpServletResponse);
//        List<Dept> depts=deptService.getDpets();
        Enumeration<String> s = httpServletRequest.getHeaderNames();
        httpServletResponse.setHeader("Content-type","text/html;charset=UTF-8");//向浏览器发送一个响应头，设置浏览器的解码方式为UTF-8

        String data = "中国";

        OutputStream stream = httpServletResponse.getOutputStream();

        stream.write(data.getBytes("UTF-8"));
        return null;
        //        ModelAndView mv = new ModelAndView();
//        // 没有回显到界面
//        mv.addObject("msg","hello world!!!");
//        mv.setViewName("/WEB-INF/views/hello.jsp");
//        return mv;
    }
}
